import java.util.concurrent.TimeUnit;

/**
 * @author : dormi330
 * @since : 2021/1/20/0020
 */
public class Main02 {
    private static int count;

    public static void main(String[] args) {

        Thread loop = new Thread(() -> {
            while (true) {
                if (Thread.interrupted()) {
                    System.out.println("break " + Thread.currentThread().getName());
                    break;
                }

                // do sth
                System.out.println(Thread.currentThread().getName() + ":" + count++);
            }
            System.out.println("exit while");
        });
        loop.setName("loop-thread");

        loop.start();
        // how to stop loop Thread?
        loop.interrupt();
    }
}

/*
输出：
break loop-thread
exit while

 */